package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.order.*;
import net.pinnoocle.playservice.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-11-11 14:13
 */

@RestController
@RequestMapping("/order")
@Api(tags = "订单管理")
@Slf4j
public class OrderController {

    @Autowired
    OrderServiceImpl orderService;

    @GetMapping("orderList")
    @ApiOperation("订单列表")
    public BaseResult<PageModel<ShopOrderListPageVo>> orderList(ShopOrderListSearchParams params){
        return new BaseResult<PageModel<ShopOrderListPageVo>>().ok(orderService.shopPcOrderList(params));
    }

    @PostMapping("offlineOrder")
    @ApiOperation("手动录入线下订单")
    public BaseResult<String> offlineOrder(@Validated @RequestBody SaveOfflineOrderParams params){
        boolean result = orderService.offlineOrder(params);
        if(result){
            return new BaseResult<String>().success("录入成功");
        }
        return new BaseResult<String>().error("录入失败");
    }

    @GetMapping("checkOutDetail")
    @ApiOperation("指定玩家结账信息页回显")
    public BaseResult<CheckOutUserOrderDetailVo> checkOutDetail(@RequestParam("userId") String userId,
                                                                @RequestParam("groupId") String groupId){
        return new BaseResult<CheckOutUserOrderDetailVo>().ok(orderService.checkOutDetail(userId,groupId));
    }

    @PostMapping("checkOutForUser")
    @ApiOperation("给指定玩家结账")
    public BaseResult<String> checkOutForUser(@Validated @RequestBody CheckOutUserOrderParams params){
        boolean result = orderService.checkOutForUser(params);
        if(result){
            return new BaseResult<String>().success("结账成功");
        }
        return new BaseResult<String>().error("结账失败");
    }
}
